﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
using BUS;
namespace CungMuaC5.Account_Company
{
    public partial class DoiMatKhau : System.Web.UI.Page
    {
        private DTO_TaiKhoan CurrentUser;
        private BUS_DoanhNghiep bus_DN = new BUS_DoanhNghiep();
        private List<DTO_ChiTietDoanhNghiep> doanhNghiep;
        BUS_TaiKhoan bus_taikhoan = new BUS_TaiKhoan();
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btSave_Click(object sender, ImageClickEventArgs e)
        {
            if (tbCurrentPassword.Text == "")
                error1.Text = "(*) bắt buộc nhập";
            else
                error1.Text = "";
            if (tbNewPassword.Text == "")
                error2.Text = "(*) bắt buộc nhập";
            else
                error2.Text = "";
            if (tbConfirmPassword.Text == "")
                error3.Text = "(*) bắt buộc nhập";
            else
                error3.Text = "";
            if (tbConfirmPassword.Text != "" && tbCurrentPassword.Text != "" && tbNewPassword.Text != "")
            {
                CurrentUser = Session.GetCurrentUser();
                int maTK = int.Parse(CurrentUser.MaTK.ToString());
                doanhNghiep = bus_DN.LayChiTietDN(maTK);
                string password=doanhNghiep[0].Password;

                if (tbCurrentPassword.Text.ToString()==password)
                {
                    if (tbNewPassword.Text == tbConfirmPassword.Text)
                    {
                        DTO_TaiKhoan temp = Session.GetCurrentUser();
                        temp.Password = tbNewPassword.Text;
                        bus_taikhoan.SavePassword(temp.Password, temp.MaTK);
                        lblThongBao.Text = "Đổi mật khẩu thành công";
                        Response.Redirect("~/Account_Company/ThongTinDN.aspx");
                    }
                    else
                        error3.Text = "Mật khẩu không khớp";
                }
                else
                    error1.Text = "Sai mmật khẩu";
            }            
        }

        protected void btCancel_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("~/Account_Company/ThongTinDN.aspx");
        }
    }
}